import warnings
warnings.warn("qturboframe.public_ui.ucf_h_ui.tabs模块已被废弃，替代模块为qturboframe.public_ui.h_ui.tabs", DeprecationWarning)

from qturboframe.lib.report.log import logger
from qturboframe.lib.ranorex.web_element.div_tag import DivTag
from qturboframe.lib.ranorex.web_element.i_tag import ITag
from ..ucf_base_element import BaseElement


class Tabs(BaseElement):
    '''hui的tab标签类'''

    def __init__(self, element_para, father=None, timeout=10000):
        super().__init__(element_para, father, timeout)
        self._element = DivTag(self._element.control)

    def select(self, tab_name):
        '''
        选择选项卡

        :Args:
         - tab_name: 选项卡的名称

        :Example:
         - 例: tabs.select('权限分配')
        '''
        tab = DivTag(self._element.find_element_by_attribute(
            'xpath', './div[@innertext=\'{}\']'.format(tab_name), timeout=self.timeout).control)
        tab.secure_click()
        logger.info('打开 {} 选项卡。'.format(tab_name))

    def close(self, tab_name):
        '''
        关闭选项卡

        :Args:
         - tab_name: 选项卡的名称

        :Example:
         - 例: tabs.close('权限分配')
        '''
        tab = DivTag(self._element.find_element_by_attribute(
            'xpath', './div[@innertext=\'{}\']'.format(tab_name), timeout=self.timeout).control)
        tab.move_to()
        tab_i = ITag(tab.find_element_by_attribute(
            'xpath', './i[@class~\'h-icon-close\']'.format(tab_name), timeout=self.timeout).control)
        tab_i.secure_click()
        logger.info('关闭当前选项卡。')
